<?php include("header.php"); 
if(isset($_POST['save_csr'])){ //print_r($_POST);
	$sql=mysql_query("INSERT INTO `my_csr` SET  `username` = '".$_REQUEST['username']."',
												`password` = '".md5($_REQUEST['password'])."',
												`roll` = '".$_REQUEST['roll']."',
												`status` = 1 ")or die(mysql_error());
	if($sql){
		$_SESSION['msg']="CSR Suscessfully Added!";
		header("location:".$_SERVER['HTTP_REFERER']); exit;
	}
}
//Delete CSR///////////////
if(isset($_REQUEST['delete_id'])){ //print_r($_POST);
	$sql=mysql_query("DELETE FROM `my_csr` WHERE `id`= '".$_REQUEST['delete_id']."' ")or die(mysql_error());
	if($sql){
		$_SESSION['msg']="CSR Suscessfully Deleted!";
		header("location:".$_SERVER['HTTP_REFERER']); exit;
	}
}
////////////////////////////
?>
<?php include("nav.php"); 
if(isset($_SESSION['msg'])){
?>
<div style="color:red; font-size:16px; text-align:center;"><?php echo $_SESSION['msg']; unset($_SESSION['msg']); ?></div>
<?php }?>
<ul class="formbox"> <center><h1 style="font-size:38px; color:#060;">Create CSR</h1></center> 
<form action="" method="post" autocomplete="off" id="form1">
<li><label>Select Roll </label>
    <select name="roll" required>
    	<option value="">Select Roll</option>
		<?php $sql1=mysql_query("SELECT * FROM `my_roll` WHERE `status` = 1 ")or die(mysql_error());
        while($row1=mysql_fetch_array($sql1)){
        ?>
        <option value="<?php echo $row1['id']; ?>"><?php echo $row1['name']; ?></option>
        <?php }?>
    </select>
</li> 
<li><label>User Id </label><input type="text" name="username"  required="required" /></li> 
<li><label>Password </label><input type="password" name="password" required  /></li> 
<li><label>  </label><input type="submit" name="save_csr" value="Submit"  /></li> 
 </form>
</ul>

<table  id="datatables" class="display">
<thead>
  <tr>
    <th scope="col">Sl.No</th>
    <th scope="col">CSR Category</th>
    <th scope="col">Userid</th>
    <th scope="col">Password</th>
    <th scope="col">Action</th>
  </tr>
</thead>
<tbody>
<?php $sl=1;
$sql1=mysql_query("SELECT * FROM `my_csr` WHERE `status` = 1 ")or die(mysql_error());
while($row=mysql_fetch_array($sql1)){
?>
  <tr>
    <td><?php echo $sl; ?></td>
    <td><?php echo get_item('my_roll','id',$row['roll'],'name'); ?></td>
    <td><?php echo $row['username']; ?></td>
    <td><?php echo $row['password']; ?></td>
    <td><a href="?delete_id=<?php echo $row['id']; ?>">Delete</a></td>
  </tr>
<?php $sl++;}?>
</tbody>
</table>




<?php include("footer.php"); ?>

